package com.example.silvercare;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

import com.example.server.SCSocketComm;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;

import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class SilverCare extends Activity {
    /** Called when the activity is first created. */

	ImageView imgView;
	SharedPreferences myprefs;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        imgView = (ImageView)findViewById(R.id.ImageView01);
        imgView.setImageResource(R.drawable.silvercare);
        
        myprefs = PreferenceManager.getDefaultSharedPreferences(this);
        final String name = myprefs.getString("namePref", null);
        final String email = myprefs.getString("emailaddressPref", null);
        
        Toast.makeText(this, "Name: "+name + "\nEmail: "+email, Toast.LENGTH_SHORT).show();
        
        if(name!=null && email!=null)
        {
            //start listening
            startService(new Intent("com.example.server.ServiceProvider"));
            startService(new Intent("com.example.server.DialogPopUpService"));
            startService(new Intent("com.example.server.LocationUpdateService"));
            
            //registor coalition
        	//Coalition coal = new Coalition();
        	//coal.register();
			
        }else
        {
        	Toast.makeText(this, "Fill username and email, then restart", Toast.LENGTH_SHORT).show();
        }
    
    }
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		super.onCreateOptionsMenu(menu);
		
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.main_option_menu, menu);
	    return true;

	}
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		super.onOptionsItemSelected(item);
		
		switch (item.getItemId()) {
		case (R.id.service):
			startActivityForResult(new Intent("com.example.server.ServiceList"), R.id.service_activity_closed);
			return true;
		case (R.id.setting):
			startActivity(new Intent(this, Setting.class));
			return true;
		case (R.id.about):
			startActivity(new Intent(this, About.class));
			return true;
		default:
			return true;
		}
	}
    
}